package com.sany.taskmanager.util;

import android.text.method.ReplacementTransformationMethod;

public class EditUtil {
    public static ReplacementTransformationMethod replacementTransformationMethod = new ReplacementTransformationMethod() {
        @Override
        protected char[] getOriginal() {
            return new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
        }

        @Override
        protected char[] getReplacement() {
            return new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
        }
    };

    /**
     * @param colorValue：#ccd099
     * @return true：深色，false：浅色
     */
    public static boolean isDarkColor(String colorValue) {
        if (colorValue == null || colorValue.length() < 7) {
            return false;
        }
        String color = colorValue.substring(1);
        int R = Integer.parseInt(color.substring(0, 2), 16);
        int G = Integer.parseInt(color.substring(2, 4), 16);
        int B = Integer.parseInt(color.substring(4, 6), 16);
        // 根据计算的结果值：>192为浅色，<=192为深色
        return (R * 0.299 + G * 0.587 + B * 0.114) <= 192;
    }
}
